<template>
	<view class="contain">
		<form @submit="fromsubmit">
			<view class="head-img">
				<image src="http://pic.soutu123.cn/element_origin_min_pic/01/54/05/335746fd1e7f644.jpg!/fw/700/quality/90/unsharp/true/compress/true" mode=""></image>
			</view>
			<view class="userinfo">
				<view class="leftinfo">用户名：</view>
				<input type="text" value="" maxlength="11" name="username" class="ipt" placeholder="请输入用户名" auto-focus/>
			</view>
			<view class="userinfo">
				<view class="leftinfo">密码：</view>
				<input type="password" value="" maxlength="11" name="pwd" class="ipt" placeholder="请输入密码"/>
			</view>
			<button type="primary" class="btn" form-type="submit">注册/登录</button>
		</form>
		<!-- #ifdef  APP-PLUS -->
			<view class="loginchoose">
					<view class="otherlogin">
						第三方账号登录
					</view>
				
					<view class="imglogo">
						<button  open-type="getUserInfo" @getuserinfo="weixininfo" data-logintype="weixin" class="btn1" >
							<image src="../../static/weixin.png" mode=""></image>
						</button>
						<button  open-type="getUserInfo" @getuserinfo="qqinfo" data-logintype="qq" class="btn1" >
							<image src="../../static/qq.png" mode=""></image>
						</button>
					</view>
			</view>
		<!-- #endif -->
	</view>
</template>

<script>
	import common from '../../common/common.js'
	export default {
		data() {
			return {
				
			}
		},
		methods: {
			fromsubmit(e){
				console.log(e)
				var username = e.detail.value.username
				var pwd = e.detail.value.pwd
				if(username==''||pwd==''){
					uni.showToast({
						icon:"error",
						title:"密码或账号不能为空",
						duration:3000
					})
				}
				uni.request({
					url:common.serverUrl+'/user/registOrLogin',
					data:{
						"password":pwd,
						"username":username
					},
					method:"POST",
					success(res) {
						console.log(res)
						if(res.data.status==200){
							var userinfo = res.data.data
							uni.setStorageSync("globaluser",userinfo)
							uni.switchTab({
								url:'../profile/profile'
							})
						}
					}
				})
			},
			weixininfo(e){
				console.log(e)
				// var userinfo = e.detail.userInfo;
				uni.login({
					provider:"weixin",
					success(res) {
						// console.log(res)
						// var code = res.code;
						// uni.request({
						// 	url:common.serverUrl+'/mpWXLogin/'+code,
						// 	method:"POST",
						// 	data:{
						// 		"avatarUrl":userinfo.avatarUrl,
						// 		"nickName":userinfo.nickName,
						// 		"whichMP":1
						// 	},
								
						// 	success(res){
						// 		// console.log(res)
						// 		var userinfo = res.data.data
						// 		console.log(userinfo)
						// 		var face = userinfo.faceImages
						// 		var nickname = userinfo.nickname
						// 		var openIdOrUid = userinfo.mpWxOpenId
						// 		uni.request({
						// 			url:common.serverUrl+'appUnionLogin/weixin',
						// 			method:"POST",
						// 			data:{
						// 				"openIdOrUid":openIdOrUid,
						// 				"nickname":nickname,
						// 				"face":face
						// 			},
						// 			success(res) {
						// 				if(res.data.status==200){
						// 					var userinfo = res.data.data
						// 					uni.setStorageSync("globaluser",userinfo)
						// 					uni.switchTab({
						// 						url:'../profile/profile'
						// 					})
						// 				}
						// 			}
						// 		})
						// 	}
						// })
					}
				})
			}
		}
	}
</script>

<style>
@import url("./register.css");
</style>
